<template>
  <div>
    <h1>{{ id ? '编辑' : '新建' }}课程</h1>
    <ele-form
      :form-data="data"
      :form-desc="fields"
      :request-fn="submit"
    ></ele-form>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Prop } from 'vue-property-decorator'

@Component({})
export default class CourseEdit extends Vue {
  @Prop({ default: '' }) id!: string
  data = {}

  fields = {
    name: { label: '课程名称', type: 'input' },
    cover: { label: '课程封面', type: 'input' }
  }

  async fetch() {
    const res = await this.$http.get('courses')
    this.data = res.data
  }

  async submit(data) {
    this.data = {}
    await this.$http.post('courses', data)
    this.$message.success('保存成功')
    this.roueter.go(-1)
  }

  created() {}
}
</script>
<style scoped></style>
